#!/usr/bin/env python

# Copyright (c) 2015-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the LICENSE file in
# the root directory of this source tree.

# Set up the logging early on in the process.
import logging
logging.basicConfig(level=logging.INFO, format='%(message)s')

# Do other ordinary imports.
import os.path
import sys

# Add the lib/ directory to $PYTHONPATH so library code can be imported.
sys.path.append(os.path.join(os.path.dirname(__file__), '../lib'))

# Parse the command-line arguments.
import optparse
parser = optparse.OptionParser(usage='usage: %prog [options]',
                               description='Validate Nuclide packages')
parser.add_option('--verbose', action='store_true', default=False, help='Verbose output')
options, args = parser.parse_args(sys.argv[1:])

verbose = options.verbose
if verbose:
    logging.getLogger().setLevel(logging.DEBUG)

# Validate package definitions
from package_manager import PackageManager
from package_linter import PackageLinter

package_manager = PackageManager()
linter = PackageLinter(package_manager.get_package_map())

if not linter.validate_packages():
    logging.info('Found package lint errors. Exiting...')
    sys.exit(1)
